<?php

namespace app\admin\controller\dict;

use app\admin\controller\AdminController;
use app\admin\service\dict\TypeService;
use app\admin\validate\dict\TypeValidate;
use think\response\Json;

class Type extends AdminController
{
    /**
     * 查看字典类型列表
     * @return Json
     */
    public function lists()
    {
        return $this->data(TypeService::getList());
    }

    /**
     * 添加字典类型
     * @return Json
     */
    public function add()
    {
        $params = (new TypeValidate())->post()->checkParam('add');
        $result =  TypeService::add($params);
        if(true === $result) {
            return $this->success([], '添加成功');
        } else {
            return $this->error(TypeService::getError());
        }
    }

    /**
     * 编辑字典类型
     * @return Json
     */
    public function edit()
    {
        $params = (new TypeValidate())->post()->checkParam('edit');
        $result = TypeService::edit($params);
        if(true === $result) {
            return $this->success([], '编辑成功');
        } else {
            return $this->error(TypeService::getError());
        }
    }

    /**
     * 删除字典类型
     * @return Json
     */
    public function delete()
    {
        $params = (new TypeValidate())->delete()->checkParam('delete');
        $result = TypeService::delete($params);
        if(true === $result) {
            return $this->success([], '删除成功');
        } else {
            return $this->error(TypeService::getError());
        }
    }

    /**
     * 字典类型详情
     * @return Json
     */
    public function detail()
    {
        $params = (new TypeValidate())->checkParam('detail');
        $result = TypeService::detail($params);
        return $this->data($result);
    }
}